export const dateFilter = function(data, format = '') {
  if (!data) return
  const dt = new Date(data)
  const y = dt.getFullYear()
  const m = (dt.getMonth() + 1).toString().padStart(2, '0')
  const d = dt.getDate().toString().padStart(2, '0')
  const h = dt.getHours().toString().padStart(2, '0')
  const mm = dt.getMinutes().toString().padStart(2, '0')
  const s = dt.getSeconds().toString().padStart(2, '0')
  if (format.toLocaleLowerCase() === 'yyyy-mm-dd' ||
    format.toLocaleLowerCase() === '') {
    return `${y}-${m}-${d}`
  } else if (format.toLocaleLowerCase() === 'yyyy/mm/dd') {
    return `${y}/${m}/${d}`
  } else if (format.toLocaleLowerCase() === 'yyyy-mm-dd hh:mm:ss') {
    return `${y}-${m}-${d} ${h}:${mm}:${s}`
  } else if (format.toLocaleLowerCase() === 'yyyy/mm/dd hh:mm:ss') {
    return `${y}/${m}/${d} ${h}:${mm}:${s}`
  } else {
    return `输入的时间格式有误`
  }
}

import { checkResultData } from './baseData'
export const checkResult = function(val) {
  for (let i = 0; i < checkResultData.length; i++) {
    if (val === checkResultData[i].value) {
      return checkResultData[i].label
    }
  }
  return val
}

export const buildingTypeFilter = function(buildingType) {
  switch (buildingType) {
    case 1: return '景'
    case 2: return '停'
    case 3: return '地'
    case 4: return '桩'
    case 5: return '防'
    default: return buildingType
  }
}

export const selectDictLabel = function(val, dictOptions) {
  val = val + ''
  for (let i = 0; i < dictOptions.length; i++) {
    if (val === dictOptions[i].dictValue) {
      return dictOptions[i].dictLabel
    }
  }
  return val
}

export const selectEnumLabel = function(val, enumOptions) {
  for (let i = 0; i < enumOptions.length; i++) {
    if (val === enumOptions[i].value) {
      return enumOptions[i].label
    }
  }
  return val
}

// 字典过滤器
export const dictFilter = function(val, list) {
  let str = ''
  for (let i = 0; i < list.length; i++) {
    if (val === list[i].value) {
      str = list[i].label
    }
  }
  return str
}
